/*
 * @Author: oreky
 * @Date: 2020-12-24 10:03:57
 * @LastEditTime: 2020-12-24 13:51:06
 * @LastEditors: oreky
 * @Description: 数组工具
 * @FilePath: \oreky-utils\src\array.ts
 */

/**
 * 从数组中移除某个元素
 * @param array 数组
 * @param item 需要剔除的元素
 */
export function remove(array: never[], item: never): void {
  const index = array.indexOf(item);
  if (index >= 0) {
    array.splice(index, 1);
  }
}

/**
 * 数组递归深拷贝
 * @param array 原数组
 */
export function deepcopy(array: any[]): any[] {
  const out = [],
    len = array.length;
  for (let i = 0; i < len; i++) {
    if (array[i] instanceof Array) {
      out[i] = deepcopy(array[i]);
    } else out[i] = array[i];
  }
  return out;
}